<template>
  <div class="main-content">
    <!-- 列表页 -->
    <div v-if="showFlag">
      <el-form :inline="true" :model="searchForm" class="form-content">
        <el-row :gutter="20" class="slt"
                :style="{justifyContent:'center'}">
          <div v-if="role === '1'">
            <el-form-item label="学号">
              <el-input v-model="searchForm.studentaccount"
                        placeholder="学号"
                        clearable></el-input>
            </el-form-item>
            <el-form-item label="学生姓名">
              <el-input
                  v-model="searchForm.studentname"
                  placeholder="学生姓名"
                  clearable>
              </el-input>
            </el-form-item>
          </div>
          <div v-if="role === '2'">
            <el-form-item label="工号">
              <el-input v-model="searchForm.mentoraccount"
                        placeholder="工号"
                        clearable></el-input>
            </el-form-item>
            <el-form-item label="导师姓名">
              <el-input
                  v-model="searchForm.mentorname"
                  placeholder='导师姓名'
                  clearable>
              </el-input>
            </el-form-item>

          </div>

          <el-form-item>
            <el-button icon="el-icon-search"
                       type="success" @click="search()">{{ '查询' }}
            </el-button>

          </el-form-item>
        </el-row>
        <el-row class="ad"
                :style="{justifyContent: contents.btnAdAllBoxPosition == '1' ? 'flex-start' : contents.btnAdAllBoxPosition == '2' ? 'center' : 'flex-end'}">
          <el-form-item>
            <!-- 按钮组 -->
            <el-button-group>
              <!-- 新增按钮 -->
              <el-button :style="{ backgroundColor: buttonColorRoleO, color: fontColorRoleO,}"
                         @click="getStudentDataList()">
                学生
              </el-button>
              <el-button :style="{ backgroundColor: buttonColorRoleT, color: fontColorRoleT,}"
                         @click="getMentorDataList()">
                导师
              </el-button>
            </el-button-group>
            <!-- 按钮组结束 -->
          </el-form-item>
        </el-row>

      </el-form>
      <div class="table-content">
        <el-table class="tables" :size="contents.tableSize" :show-header="contents.tableShowHeader"
                  :header-row-style="headerRowStyle" :header-cell-style="headerCellStyle"
                  :border="contents.tableBorder"
                  :fit="contents.tableFit"
                  :stripe="contents.tableStripe"
                  :row-style="rowStyle"
                  :cell-style="cellStyle"
                  :style="{width: '100%',fontSize:contents.tableContentFontSize,color:contents.tableContentFontColor}"
                  v-if=true
                  :data="dataList"
                  v-loading="dataListLoading">
          <el-table-column v-if="contents.tableSelection"
                           type="selection"
                           header-align="center"
                           align="center"
                           width="50">
          </el-table-column>
          <el-table-column label="索引" v-if="contents.tableIndex" type="index" width="50"/>

          <el-table-column :sortable="contents.tableSortable" :align="contents.tableAlign"
                           header-align="center"
                           label="学号/工号">
            <template v-slot:="scope">
              {{ role === "1" ? scope.row.studentaccount : scope.row.mentoraccount }}
            </template>
          </el-table-column>
          <el-table-column :sortable="contents.tableSortable" :align="contents.tableAlign"
                           header-align="center"
                           label="姓名">
            <template v-slot="scope">
              {{ role === "1" ? scope.row.studentname : scope.row.mentorname }}
            </template>
          </el-table-column>

          <el-table-column :sortable="contents.tableSortable" :align="contents.tableAlign"
                           v-if="role === '1'"
                           header-align="center"
                           label="班级">
            <template v-slot="scope">
              {{ scope.row.studentclass }}
            </template>
          </el-table-column>

          <el-table-column :sortable="contents.tableSortable" :align="contents.tableAlign"
                           header-align="center"
                           label="学院">
            <template v-slot="scope">
              {{ role === "1" ? scope.row.studentcollege : scope.row.mentorcollege }}
            </template>
          </el-table-column>

          <el-table-column :sortable="contents.tableSortable" :align="contents.tableAlign"
                           header-align="center"
                           label="性别">
            <template v-slot="scope">
              {{ scope.row.gender }}
            </template>
          </el-table-column>

          <el-table-column :sortable="contents.tableSortable" :align="contents.tableAlign"
                           v-if="role === '2'"
                           header-align="center"
                           label="已有学生">
            <template v-slot="scope">
              {{ scope.row.selectedquota }}
            </template>
          </el-table-column>

          <el-table-column :sortable="contents.tableSortable" :align="contents.tableAlign"
                           v-if="role === '2'"
                           header-align="center"
                           label="导师名额">
            <template v-slot="scope">
              {{ scope.row.mentorquota }}
            </template>
          </el-table-column>


        </el-table>
        <el-pagination
            clsss="pages"
            :layout="layouts"
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :current-page="pageIndex"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="Number(contents.pageEachNum)"
            :total="totalPage"
            :small="contents.pageStyle"
            class="pagination-content"
            :background="contents.pageBtnBG"
            :style="{textAlign:contents.pagePosition==1?'left':contents.pagePosition==2?'center':'right'}"
        ></el-pagination>
      </div>
    </div>

  </div>
</template>
<script>
export default {
  data() {
    return {
      searchForm: {
        key: ""
      },

      value: '',

      form: {},
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      showFlag: true,
      sfshVisiable: false,
      shForm: {},
      chartVisiable: false,
      addOrUpdateFlag: false,
      fileList: [],
      contents: {
        "searchBtnFontColor": "rgba(49,47,47,0.88)",
        "pagePosition": "1",
        "inputFontSize": "14px",
        "inputBorderRadius": "5px",
        "tableBtnDelFontColor": "#333",
        "searchBtnHeight": "40px",
        "inputIconColor": "#C0C4CC",
        "searchBtnBorderRadius": "5px",
        "tableStripe": false,
        "tableBtnDelBgColor": "rgba(214, 186, 232, 1)",
        "tableSize": "medium",
        "searchBtnBorderStyle": "solid",
        "tableSelection": true,
        "searchBtnBorderWidth": "1px",
        "tableContentFontSize": "14px",
        "searchBtnBgColor": "rgba(218,229,223,0.66)",
        "inputTitleSize": "16px",
        "pageJumper": true,
        "tableBtnDetailFontColor": "#333",
        "tableBtnHeight": "40px",
        "pagePager": true,
        "searchBtnBorderColor": "#DCDFE6",
        "tableHeaderFontColor": "rgba(47,44,44,0.76)",// 列首字体颜色
        "tableBtnBorderRadius": "5px",

        "btnAdAllDelFontColor": "#333",
        "btnAdAllWarnFontColor": "#ffffff",// 字体颜色
        "btnAdAllBorderColor": "#b2ac68",// 左上按钮边框颜色
        "btnAdAllHeight": "40px",
        "btnAdAllWarnBgColor": "rgba(75,222,146,0.8)",
        "btnAdAllFontWeight": 550,
        "btnAdAllBorderWidth": "1px",
        "btnAdAllAddBgColor": "rgba(75,222,146,0.8)",//背景颜色

        "tableStripeFontColor": "#606266",
        "tableBtnBorderStyle": "solid",
        "inputHeight": "40px",
        "btnAdAllBorderRadius": "5px",
        "btnAdAllDelBgColor": "rgba(255, 76, 10, 0.71)",
        "pagePrevNext": true,
        "searchBtnFont": "1",
        "tableIndex": true,
        "btnAdAllIcon": "1",
        "tableSortable": true,
        "pageSizes": true,
        "tableFit": true,
        "pageBtnBG": true,
        "searchBtnFontSize": "14px",
        "tableBtnEditBgColor": "rgba(202, 235, 202, 1)",
        "inputBorderWidth": "1px",
        "inputFontPosition": "2",
        "inputFontColor": "#333",
        "pageEachNum": 10,
        "tableHeaderBgColor": "rgb(255,255,255)",//列首背景
        "inputTitleColor": "rgba(54,55,58,0.88)",
        "btnAdAllBoxPosition": "1",
        "tableBtnDetailBgColor": "rgba(173, 241, 242, 1)",
        "inputIcon": "0",
        "searchBtnIconPosition": "1",
        "btnAdAllFontSize": "14px",
        "inputBorderStyle": "solid",
        "inputBgColor": "rgba(255,255,255,0.66)",
        "pageStyle": false,
        "pageTotal": true,
        "btnAdAllAddFontColor": "#333",
        "tableBtnFont": "1",
        "tableContentFontColor": "#29292f",//表格内字体
        "inputBorderColor": "#DCDFE6",
        "tableShowHeader": true,
        "tableBtnFontSize": "14px",
        "tableBtnBorderColor": "#DCDFE6",
        "inputIconPosition": "1",
        "tableBorder": true,
        "btnAdAllBorderStyle": "solid",
        "tableBtnBorderWidth": "1px",
        "tableStripeBgColor": "#F5F7FA",
        "tableBtnEditFontColor": "#333",
        "tableAlign": "center"
      },
      layouts: '',

      role: "2",
    };
  },
  async created() {
    await this.init();
    await this.contentStyleChange()
    await this.getStudentDataList();
  },
  mounted() {

  },
  filters: {
    htmlfilter: function (val) {
      return val.replace(/<[^>]*>/g).replace(/undefined/g, '');
    }
  },
  computed: {
    buttonColorRoleO() {
      return this.role === '1' ? '#6dc7a1' : '#ffffff'; // role 为 '1' 时为绿色，否则为红色
    },
    buttonColorRoleT() {
      return this.role === '2' ? '#6dc7a1' : '#ffffff'; // role 为 '1' 时为绿色，否则为红色
    },
    fontColorRoleO() {
      return this.role === '1' ? '#ffffff' : '#000000';
    },
    fontColorRoleT() {
      return this.role === '2' ? '#ffffff' : '#000000';
    }
  },
  methods: {
    /*组件设计方法*/
    contentStyleChange() {
      this.contentSearchStyleChange()
      this.contentBtnAdAllStyleChange()
      this.contentSearchBtnStyleChange()
      this.contentPageStyleChange()
    },
    contentSearchStyleChange() {
      this.$nextTick(() => {
        document.querySelectorAll('.form-content .slt .el-input__inner').forEach(el => {
          let textAlign = 'left'
          if (this.contents.inputFontPosition == 2) textAlign = 'center'
          if (this.contents.inputFontPosition == 3) textAlign = 'right'
          el.style.textAlign = textAlign
          el.style.height = this.contents.inputHeight
          el.style.lineHeight = this.contents.inputHeight
          el.style.color = this.contents.inputFontColor
          el.style.fontSize = this.contents.inputFontSize
          el.style.borderWidth = this.contents.inputBorderWidth
          el.style.borderStyle = this.contents.inputBorderStyle
          el.style.borderColor = this.contents.inputBorderColor
          el.style.borderRadius = this.contents.inputBorderRadius
          el.style.backgroundColor = this.contents.inputBgColor
        })
        if (this.contents.inputTitle) {
          document.querySelectorAll('.form-content .slt .el-form-item__label').forEach(el => {
            el.style.color = this.contents.inputTitleColor
            el.style.fontSize = this.contents.inputTitleSize
            el.style.lineHeight = this.contents.inputHeight
          })
        }
        setTimeout(() => {
          document.querySelectorAll('.form-content .slt .el-input__prefix').forEach(el => {
            el.style.color = this.contents.inputIconColor
            el.style.lineHeight = this.contents.inputHeight
          })
          document.querySelectorAll('.form-content .slt .el-input__suffix').forEach(el => {
            el.style.color = this.contents.inputIconColor
            el.style.lineHeight = this.contents.inputHeight
          })
          document.querySelectorAll('.form-content .slt .el-input__icon').forEach(el => {
            el.style.lineHeight = this.contents.inputHeight
          })
        }, 10)

      })
    },
    // 搜索按钮
    contentSearchBtnStyleChange() {
      this.$nextTick(() => {
        document.querySelectorAll('.form-content .slt .el-button--success').forEach(el => {
          el.style.height = this.contents.searchBtnHeight
          el.style.color = this.contents.searchBtnFontColor
          el.style.fontSize = this.contents.searchBtnFontSize
          el.style.borderWidth = this.contents.searchBtnBorderWidth
          el.style.borderStyle = this.contents.searchBtnBorderStyle
          el.style.borderColor = this.contents.searchBtnBorderColor
          el.style.borderRadius = this.contents.searchBtnBorderRadius
          el.style.backgroundColor = this.contents.searchBtnBgColor
        })
      })
    },
    // 新增、批量删除
    contentBtnAdAllStyleChange() {
      this.$nextTick(() => {
        document.querySelectorAll('.form-content .ad .el-button--success').forEach(el => {
          el.style.height = this.contents.btnAdAllHeight
          el.style.color = this.contents.btnAdAllAddFontColor
          el.style.fontSize = this.contents.btnAdAllFontSize
          el.style.borderWidth = this.contents.btnAdAllBorderWidth
          el.style.borderStyle = this.contents.btnAdAllBorderStyle
          el.style.borderColor = this.contents.btnAdAllBorderColor
          el.style.borderRadius = this.contents.btnAdAllBorderRadius
          el.style.backgroundColor = this.contents.btnAdAllAddBgColor
        })
        document.querySelectorAll('.form-content .ad .el-button--danger').forEach(el => {
          el.style.height = this.contents.btnAdAllHeight
          el.style.color = this.contents.btnAdAllDelFontColor
          el.style.fontSize = this.contents.btnAdAllFontSize
          el.style.borderWidth = this.contents.btnAdAllBorderWidth
          el.style.borderStyle = this.contents.btnAdAllBorderStyle
          el.style.borderColor = this.contents.btnAdAllBorderColor
          el.style.borderRadius = this.contents.btnAdAllBorderRadius
          el.style.backgroundColor = this.contents.btnAdAllDelBgColor
        })
        document.querySelectorAll('.form-content .ad .el-button--warning').forEach(el => {
          el.style.height = this.contents.btnAdAllHeight
          el.style.color = this.contents.btnAdAllWarnFontColor
          el.style.fontSize = this.contents.btnAdAllFontSize
          el.style.borderWidth = this.contents.btnAdAllBorderWidth
          el.style.borderStyle = this.contents.btnAdAllBorderStyle
          el.style.borderColor = this.contents.btnAdAllBorderColor
          el.style.borderRadius = this.contents.btnAdAllBorderRadius
          el.style.backgroundColor = this.contents.btnAdAllWarnBgColor
        })
      })
    },
    // 表格
    rowStyle({row, rowIndex}) {
      if (rowIndex % 2 == 1) {
        if (this.contents.tableStripe) {
          return {color: this.contents.tableStripeFontColor}
        }
      } else {
        return ''
      }
    },
    cellStyle({row, rowIndex}) {
      if (rowIndex % 2 == 1) {
        if (this.contents.tableStripe) {
          return {backgroundColor: this.contents.tableStripeBgColor}
        }
      } else {
        return ''
      }
    },
    headerRowStyle({row, rowIndex}) {
      return {color: this.contents.tableHeaderFontColor}
    },
    headerCellStyle({row, rowIndex}) {
      return {backgroundColor: this.contents.tableHeaderBgColor}
    },

    // 分页
    contentPageStyleChange() {
      let arr = []

      if (this.contents.pageTotal) arr.push('total')
      if (this.contents.pageSizes) arr.push('sizes')
      if (this.contents.pagePrevNext) {
        arr.push('prev')
        if (this.contents.pagePager) arr.push('pager')
        arr.push('next')
      }
      if (this.contents.pageJumper) arr.push('jumper')
      this.layouts = arr.join()
      this.contents.pageEachNum = 10
    },

    init() {
      this.genderOptions = "男,女".split(',')
    },
    search() {
      this.pageIndex = 1;
      if (this.role === '1') {
        this.getStudentDataList();
      } else {
        this.getMentorDataList()
      }

    },

    confirmMatch(row) {
      this.$confirm('确定匹配', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.match(row); // 用户确认后调用结束当前轮的方法
      }).catch(() => {
        this.$message.info('操作已取消'); // 用户取消操作
      });
    },

    // 获取数据列表
    async getStudentDataList() {
      this.dataListLoading = true;
      let params = {
        current: this.pageIndex,
        mentoraccount: "",
        pageSize: this.pageSize,
        round: "",
        sortField: "",
        sortOrder: "",
        studentaccount: "",
        studentname: "",
      }
      if (this.searchForm.studentaccount !== '' && this.searchForm.studentaccount !== undefined) {
        params['studentaccount'] = this.searchForm.studentaccount
      }
      if (this.searchForm.studentname !== '' && this.searchForm.studentname !== undefined) {
        params['studentname'] = this.searchForm.studentname
      }
      if (this.searchForm.round !== '' && this.searchForm.round !== undefined) {
        params['round'] = this.searchForm.round
      }
      await this.$http({
        url: "/admin/student/list/page/no-mentor",
        method: "post",
        data: params
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.role = "1"
          this.dataList = data.data.records;
          this.totalPage = Number(data.data.total);
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },

    async getMentorDataList() {
      this.pageIndex = 1
      let params = {
        current: this.pageIndex,
        mentoraccount: "",
        mentorname:"",
        pageSize: this.pageSize,
        round: "",
        sortField: "",
        sortOrder: "",
        studentaccount: "",
        studentname: "",
      }
      if (this.searchForm.mentoraccount !== '' && this.searchForm.mentoraccount !== undefined) {
        params['mentoraccount'] = this.searchForm.mentoraccount
      }
      if (this.searchForm.mentorname !== '' && this.searchForm.mentorname !== undefined) {
        params['mentorname'] = this.searchForm.mentorname
      }
      if (this.searchForm.round !== '' && this.searchForm.round !== undefined) {
        params['round'] = this.searchForm.round
      }
      await this.$http({
        url: "/admin/mentor/list/page/has-quota",
        method: "post",
        data: params
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.role = "2"
          this.dataList = data.data.records;
          this.totalPage = Number(data.data.total);
        }
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      if (this.role === '1') {
        this.getStudentDataList();
      } else {
        this.getMentorDataList()
      }
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      if (this.role === '1') {
        this.getStudentDataList();
      } else {
        this.getMentorDataList()
      }
    },

    //索引
    indexMethod(index) {
      return (Number(this.pageIndex) - 1) * Number(this.pageSize) + index + 1;
    },
  }
};
</script>
<style lang="scss" scoped>
.slt {
  margin: 0 !important;
  display: flex;
}

.ad {
  margin: 0 !important;
  display: flex;
}

.pages {
  & /deep/ el-pagination__sizes {
    & /deep/ el-input__inner {
      height: 22px;
      line-height: 22px;
    }
  }
}


.el-button + .el-button {
  margin: 0;
}

.tables {
  & /deep/ .el-button--success {
    height: 40px;
    color: #333;
    font-size: 14px;
    border-width: 1px;
    border-style: solid;
    border-color: #DCDFE6;
    border-radius: 20px;
    background-color: rgba(173, 241, 242, 1);
  }

  & /deep/ .el-button--primary {
    height: 40px;
    color: #333;
    font-size: 14px;
    border-width: 1px;
    border-style: solid;
    border-color: #DCDFE6;
    border-radius: 20px;
    background-color: rgba(202, 235, 202, 1);
  }

  & /deep/ .el-button--danger {
    height: 40px;
    color: #333;
    font-size: 14px;
    border-width: 1px;
    border-style: solid;
    border-color: #DCDFE6;
    border-radius: 20px;
    background-color: rgba(214, 186, 232, 1);
  }

  & /deep/ .el-button {
    margin: 4px;
  }
}

</style>
